package com.beiing.tianshuai.tianshuai.interest;


import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.beiing.tianshuai.tianshuai.R;
import com.beiing.tianshuai.tianshuai.activity.MainActivity;
import com.beiing.tianshuai.tianshuai.adapter.InterestMainAdapter;
import com.beiing.tianshuai.tianshuai.app.AppConstant;
import com.beiing.tianshuai.tianshuai.app.HttpRequestConstant;
import com.beiing.tianshuai.tianshuai.entity.CodeBean;
import com.beiing.tianshuai.tianshuai.entity.UserInfoBean;
import com.beiing.tianshuai.tianshuai.fragment.BaseLazyLoadFragment;
import com.beiing.tianshuai.tianshuai.interest.entity.InterestBean;
import com.beiing.tianshuai.tianshuai.interest.presenter.InterestPresenter;
import com.beiing.tianshuai.tianshuai.interest.view.InterestViewImpl;
import com.beiing.tianshuai.tianshuai.mine.ui.LoginActivity;
import com.beiing.tianshuai.tianshuai.mine.ui.NewPersonalIndexActivity;
import com.beiing.tianshuai.tianshuai.rx.MsgEvent;
import com.beiing.tianshuai.tianshuai.rx.RxBus;
import com.beiing.tianshuai.tianshuai.util.DensityUtils;
import com.beiing.tianshuai.tianshuai.util.LogUtils;
import com.beiing.tianshuai.tianshuai.util.NetBitmapUtils;
import com.beiing.tianshuai.tianshuai.widget.CustomProgressDialog;
import com.beiing.tianshuai.tianshuai.widget.MyRefreshHeader;
import com.beiing.tianshuai.tianshuai.widget.RecycleViewDivider;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshFooter;
import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.constant.RefreshState;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.listener.OnMultiPurposeListener;
import com.tencent.connect.share.QQShare;
import com.tencent.connect.share.QzoneShare;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.tencent.open.utils.ThreadManager;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
import com.tencent.tauth.UiError;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.bingoogolapple.bgabanner.BGAOnNoDoubleClickListener;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * Create by Jinni 2017-11-19
 * <p>
 * 描述：兴趣列表页 根据type来展示不同类型的视频内容
 */
public class InterestContentFragment extends BaseLazyLoadFragment implements InterestViewImpl {

    @BindView(R.id.rl_empty_warning)
    RelativeLayout mEmptyWarning;
    @BindView(R.id.interest_header)
    MyRefreshHeader mInterestHeader;
    @BindView(R.id.rv_interest)
    RecyclerView mRvInterest;
    @BindView(R.id.interest_footer)
    ClassicsFooter mInterestFooter;
    @BindView(R.id.srl_my_refresh_layout)
    SmartRefreshLayout mSrlMyRefreshLayout;

    private static final String TAG = "InterestContentFragment";
    private static final String URL = "http://www.tianshuai.com.cn/index.php/Home/video/video_web/id/";

    /**
     * 分页最大容量
     */
    private static final int PAGE_SIZE = 15;

    /**
     * 当前分页的视频类别
     */
    private String mType;

    /**
     * 布局
     */
    private View mContentView;

    /**
     * 判断是否为刷新状态
     */
    private boolean isRefresh;

    /**
     * 判断是否加载完全部的数据
     */
    private boolean isLoadFinished;

    /**
     * 第三方分享
     */
    private Tencent mTencent;

    /**
     * 当前分页的页码
     */
    private int pageNum = 1;

    /**
     * 列表页数据网络重连次数
     */
    private int retryConnect;

    private InterestPresenter mPresenter;
    private InterestMainAdapter mAdapter;
    private Dialog bottomDialog;
    private Bitmap thumb;
    private RxBus rxBus;


    /**
     * 分享监听事件
     */
    private IUiListener mIUiListener = new IUiListener() {
        @Override
        public void onComplete(Object o) {
            showShortText("分享成功");
        }

        @Override
        public void onError(UiError uiError) {
            showShortText("分享失败");
        }

        @Override
        public void onCancel() {
            showShortText("取消分享");
        }
    };

    public static InterestContentFragment getInstance(String typeName) {
        InterestContentFragment fragment = new InterestContentFragment();
        Bundle args = new Bundle();
        args.putString("type", typeName);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mTencent = Tencent.createInstance("1106377834", mContext);
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        mContext = getActivity();
        if (mContentView == null) {
            mContentView = inflater.inflate(R.layout.fragment_interest_content, container, false);
            mUnbinder = ButterKnife.bind(this, mContentView);
            Bundle arguments = getArguments();
            if (arguments != null) {
                mType = arguments.getString("type");
            }
            mPresenter = new InterestPresenter(this);

            initRefreshLayout();
            initRecyclerView();
            initListener();
            initRxBus();

            isPrepared = true;

            lazyLoad();
        }

        //因为共用一个Fragment视图，所以当前这个视图已被加载到Activity中，必须先清除后再加入Activity
        ViewGroup parent = (ViewGroup) mContentView.getParent();
        if (parent != null) {
            parent.removeView(mContentView);
        }

        return mContentView;
    }

    /**
     * 初始化refresh layout
     * 设置下拉和上拉动作的listener
     */
    private void initRefreshLayout() {
        mSrlMyRefreshLayout.setRefreshHeader(new MyRefreshHeader(mContext));
        mSrlMyRefreshLayout.setRefreshFooter(new ClassicsFooter(mContext));
        mSrlMyRefreshLayout.setOnMultiPurposeListener(new OnMultiPurposeListener() {
            @Override
            public void onHeaderPulling(RefreshHeader header, float percent, int offset, int headerHeight, int extendHeight) {

            }

            @Override
            public void onHeaderReleasing(RefreshHeader header, float percent, int offset, int headerHeight, int extendHeight) {

            }

            @Override
            public void onHeaderStartAnimator(RefreshHeader header, int headerHeight, int extendHeight) {
                mRvInterest.setNestedScrollingEnabled(false);
            }

            @Override
            public void onHeaderFinish(RefreshHeader header, boolean success) {
                mRvInterest.setNestedScrollingEnabled(true);
            }

            @Override
            public void onFooterPulling(RefreshFooter footer, float percent, int offset, int footerHeight, int extendHeight) {

            }

            @Override
            public void onFooterReleasing(RefreshFooter footer, float percent, int offset, int footerHeight, int extendHeight) {

            }

            @Override
            public void onFooterStartAnimator(RefreshFooter footer, int footerHeight, int extendHeight) {

            }

            @Override
            public void onFooterFinish(RefreshFooter footer, boolean success) {

            }

            @Override
            public void onLoadmore(RefreshLayout refreshlayout) {
                if (!isLoadFinished) {
                    pageNum++;
                    List<InterestBean.DataBean.VideoBean> list = mAdapter.getList();
                    String lastId = list.get(list.size() - 1).getId();
                    mPresenter.getInterestInfo(mType, String.valueOf(PAGE_SIZE), lastId, UserInfoBean.getUid(mContext), pageNum);
                    mSrlMyRefreshLayout.finishLoadmore(true);
                }
            }

            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                pageNum = 1;
                isRefresh = true;
                isLoadFinished = false;
                mPresenter.getInterestInfo(mType, String.valueOf(PAGE_SIZE), "", UserInfoBean.getUid(mContext), pageNum);
            }

            @Override
            public void onStateChanged(RefreshLayout refreshLayout, RefreshState oldState, RefreshState newState) {

            }
        });
    }

    private void initRecyclerView() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false);
        mRvInterest.setNestedScrollingEnabled(false);
        mRvInterest.setLayoutManager(linearLayoutManager);
        //绘制item间的分割线，
        mRvInterest.addItemDecoration(
                new RecycleViewDivider(
                        mContext, LinearLayoutManager.HORIZONTAL, DensityUtils.dp2px(mContext, 1f),
                        ContextCompat.getColor(mContext, R.color.divider_gray_light_efefef))
        );
        mAdapter = new InterestMainAdapter(mContext);
        mRvInterest.setAdapter(mAdapter);
    }

    /**
     * 初始化监听者
     */
    private void initListener() {
//        mRvInterest.addOnScrollListener(new RecyclerView.OnScrollListener() {
//
//            @Override
//            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
//                super.onScrolled(recyclerView, dx, dy);
//                LogUtils.i("dx:" + dx + "\ndy:" + dy, TAG);
//                int firstVisibleItemPosition = ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
//                InterestFragment parentFragment = (InterestFragment) getParentFragment();
//                if (parentFragment != null) {
//                    if (firstVisibleItemPosition == 0) {
//                        if (!InterestFragment.isToolbarShow) {
//                            InterestFragment.isToolbarShow = true;
//                            parentFragment.showToolbar();
//                        }
//                    } else {
//                        if (mDisy > 25 && InterestFragment.isToolbarShow) {
//                            InterestFragment.isToolbarShow = false;
//                            parentFragment.hideToolbar();
//                            mDisy = 0;
//                        }
//                        if (mDisy < - 25 && !InterestFragment.isToolbarShow) {
//                            InterestFragment.isToolbarShow = true;
//                            parentFragment.showToolbar();
//                            mDisy = 0;
//                        }
//                    }
//
//                    if ((InterestFragment.isToolbarShow && dy > 0) || (!InterestFragment.isToolbarShow && dy < 0)) {
//                        mDisy += dy;
//                    }
//                }
//            }
//        });

        // 设置头像和昵称的点击事件
        mAdapter.setOnAvatarClickListener(new InterestMainAdapter.OnAvatarClickListener() {
            @Override
            public void onAvatarClick(InterestBean.DataBean.VideoBean bean, int position) {
                Intent intent = new Intent(mContext, NewPersonalIndexActivity.class);
                intent.putExtra("uid", bean.getUid());
                startActivity(intent);
            }
        });

        // 设置更多按钮的点击事件
        mAdapter.setOnMoreClickListener(new InterestMainAdapter.OnMoreClickListener() {
            @Override
            public void onMoreClick(InterestBean.DataBean.VideoBean bean, int position) {
                showShareDialog(bean);
            }
        });

        // 设置列表中item的点击事件 进入视频详情页
        mAdapter.setOnItemClickListener(new InterestMainAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(InterestBean.DataBean.VideoBean bean, int position) {
                Intent intent = new Intent(mContext, InterestVideoDetailActivity.class);
                intent.putExtra("vid", bean.getId());
                intent.putExtra("typeName", bean.getTypename());
                startActivity(intent);
            }
        });
    }

    @Override
    protected void lazyLoad() {
        if (!isPrepared || isLoadedOnce || !isVisible) {
            return;
        }
        mPresenter.getInterestInfo(mType, String.valueOf(PAGE_SIZE), "", UserInfoBean.getUid(mContext), pageNum);
    }

    @Override
    public void showProgress() {
        if (!isRefresh && !mSrlMyRefreshLayout.isLoading()) {
            CustomProgressDialog.showLoading(mContext, "正在努力加载，请稍后...", true);
        }
    }

    @Override
    public void hideProgress() {
        CustomProgressDialog.stopLoading();
    }

    @Override
    public void onRequestSuccess(InterestBean interestBean) {
        switch (interestBean.getCode()) {
            case 200:
                List<InterestBean.DataBean.VideoBean> videoBeanList = interestBean.getData().getVideo();
                LogUtils.i(videoBeanList.toString(), TAG);
                if (isRefresh) {
                    isRefresh = false;
                    int size = videoBeanList.size();
                    if (size > 0) {
                        mEmptyWarning.setVisibility(View.GONE);
                        mAdapter.updateData(videoBeanList);
                    }
                    mSrlMyRefreshLayout.finishRefresh();
                } else {
                    int dataSize = videoBeanList.size();
                    if (dataSize > 0) {
                        mEmptyWarning.setVisibility(View.GONE);
                        isLoadFinished = false;
                        mAdapter.appendData(videoBeanList);
                    } else {
                        isLoadFinished = true;
                        if (mAdapter.getList().isEmpty()) {
                            mEmptyWarning.setVisibility(View.VISIBLE);
                        }
                        mSrlMyRefreshLayout.setLoadmoreFinished(true);
                    }
                }
                break;
            case 400:
                showShortText("暂无数据");
                break;
            case 403:
                showShortText("获取参数失败");
                break;
            case 404:
                showShortText("获取数据失败");
                break;
        }
        isLoadedOnce = true;
    }

    @Override
    public void onRequestFailed(Throwable throwable) {
        //获取兴趣列表失败
        if ((retryConnect < 5)) {
            retryConnect++;
            mPresenter.getInterestInfo(mType, String.valueOf(PAGE_SIZE), "", UserInfoBean.getUid(mContext), pageNum);
        } else {
            retryConnect = 0;
            showShortText("请求数据失败");
            if (mSrlMyRefreshLayout.isRefreshing()) {
                mSrlMyRefreshLayout.finishRefresh();
            }
        }
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        isVisible = isVisibleToUser;
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    /**
     * 弹出分享提示框
     *
     * @param bean 要分享的视频内容
     */
    private void showShareDialog(final InterestBean.DataBean.VideoBean bean) {
        bottomDialog = new Dialog(mContext, R.style.BottomDialog);
        @SuppressLint("InflateParams") View contentView = LayoutInflater.from(mContext).inflate(R.layout.dialog_interest_bottom_share, null);
        RadioButton weChatFriends = contentView.findViewById(R.id.rb_wechat_friends);
        RadioButton weChatCircle = contentView.findViewById(R.id.rb_wechat_circle);
        RadioButton qqFriends = contentView.findViewById(R.id.rb_qq_friends);
        RadioButton qqZone = contentView.findViewById(R.id.rb_qzone);
        Button btnShareFollowed = contentView.findViewById(R.id.btn_share_followed);
        Button btnShareUp = contentView.findViewById(R.id.btn_share_up);
        Drawable upDrawableTop = getResources().getDrawable(0 != bean.getPraise() ?
                R.drawable.ic_share_up_checked : R.drawable.ic_share_up);
        upDrawableTop.setBounds(0, 0, upDrawableTop.getMinimumWidth(), upDrawableTop.getMinimumHeight());
        btnShareUp.setCompoundDrawables(null,
                upDrawableTop,
                null, null);
        Button btnShareDown = contentView.findViewById(R.id.btn_share_down);
        Drawable downDrawableTop = getResources().getDrawable(2 == bean.getPraise() ?
                R.drawable.ic_share_down_checked : R.drawable.ic_share_down);
        downDrawableTop.setBounds(0, 0, downDrawableTop.getMinimumWidth(), downDrawableTop.getMinimumHeight());
        btnShareDown.setCompoundDrawables(null,
                downDrawableTop,
                null, null);
        Button btnShareReport = contentView.findViewById(R.id.btn_share_report);
        weChatFriends.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                shareToWeChatWithWebPage(bean, mContext, URL + bean.getId(), bean.getTitle(), bean.getContent(), 0);
                bottomDialog.dismiss();
            }
        });
        weChatCircle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                shareToWeChatWithWebPage(bean, mContext, URL + bean.getId(), bean.getTitle(), bean.getContent(), 1);
                bottomDialog.dismiss();
            }
        });
        qqFriends.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                shareToQQ(bean.getTitle(), bean.getContent(), URL + bean.getId());
                bottomDialog.dismiss();
            }
        });
        qqZone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                shareToQZone(bean.getTitle(), bean.getContent(), URL + bean.getId());
                bottomDialog.dismiss();
            }
        });
        btnShareFollowed.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            }
        });
        btnShareUp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String uid = UserInfoBean.getUid(mContext);
                if (TextUtils.isEmpty(uid)) {
                    toLogin();
                    return;
                }
                switch (bean.getPraise()) {
                    case 0:
                        bean.setPraise(1);
                        if (view instanceof TextView) {
                            Button btnUp = (Button) view;
                            Drawable upDrawableTop = getResources().getDrawable(R.drawable.ic_share_up_checked);
                            upDrawableTop.setBounds(0, 0, upDrawableTop.getMinimumWidth(), upDrawableTop.getMinimumHeight());
                            btnUp.setCompoundDrawables(null, upDrawableTop, null, null);
                        }
                        mPresenter.getPriseResult(bean.getId(), UserInfoBean.getUid(mContext), "1");
                        break;
                    default:
                        bean.setPraise(0);
                        if (view instanceof TextView) {
                            Button btnUp = (Button) view;
                            Drawable downDrawableTop = getResources().getDrawable(R.drawable.ic_share_up);
                            downDrawableTop.setBounds(0, 0, downDrawableTop.getMinimumWidth(), downDrawableTop.getMinimumHeight());
                            btnUp.setCompoundDrawables(null, downDrawableTop, null, null);
                        }
                        mPresenter.getPriseResult(bean.getId(), UserInfoBean.getUid(mContext), "1");
                        break;
//                    case 2:
//                        showShortText( "您已经踩过这个视频咯~");
//                        break;
                }
            }
        });
        btnShareDown.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String uid = UserInfoBean.getUid(mContext);
                if (TextUtils.isEmpty(uid)) {
                    toLogin();
                    return;
                }
                switch (bean.getPraise()) {
                    case 0:
                        bean.setPraise(2);
                        if (view instanceof TextView) {
                            Button btnUp = (Button) view;
                            Drawable upDrawableTop = getResources().getDrawable(R.drawable.ic_share_down_checked);
                            upDrawableTop.setBounds(0, 0, upDrawableTop.getMinimumWidth(), upDrawableTop.getMinimumHeight());
                            btnUp.setCompoundDrawables(null, upDrawableTop, null, null);
                        }
                        mPresenter.getPriseResult(bean.getId(), UserInfoBean.getUid(mContext), "2");
                        break;
                    case 2:
                        bean.setPraise(0);
                        if (view instanceof TextView) {
                            Button btnUp = (Button) view;
                            Drawable downDrawableTop = getResources().getDrawable(R.drawable.ic_share_down);
                            downDrawableTop.setBounds(0, 0, downDrawableTop.getMinimumWidth(), downDrawableTop.getMinimumHeight());
                            btnUp.setCompoundDrawables(null, downDrawableTop, null, null);
                        }
                        mPresenter.getPriseResult(bean.getId(), UserInfoBean.getUid(mContext), "2");
                        break;
                    case 1:
                        showShortText("您已经赞过这个视频咯~");
                        break;
                    default:
                        break;
                }
            }
        });

        btnShareReport.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String uid = UserInfoBean.getUid(mContext);
                if (TextUtils.isEmpty(uid)) {
                    toLogin();
                    return;
                }
                bottomDialog.dismiss();
                showReportDialog(bean);
            }
        });

        bottomDialog.setContentView(contentView);
        ViewGroup.LayoutParams layoutParams = contentView.getLayoutParams();
        layoutParams.width = getResources().getDisplayMetrics().widthPixels;
        contentView.setLayoutParams(layoutParams);
        Window window = bottomDialog.getWindow();
        if (window != null) {
            window.setGravity(Gravity.BOTTOM);
            window.setWindowAnimations(R.style.BottomDialog_Animation);
        }
        bottomDialog.show();
        bottomDialog.setCanceledOnTouchOutside(true);
    }

    /**
     * 弹出举报提示框
     *
     * @param bean 要举报的视频内容
     */
    private void showReportDialog(final InterestBean.DataBean.VideoBean bean) {
        bottomDialog = new Dialog(mContext, R.style.BottomDialog);
        @SuppressLint("InflateParams") final View contentView = LayoutInflater.from(mContext).inflate(R.layout.dialog_interest_bottom_report, null);
        final RadioGroup reportTypeGroup = contentView.findViewById(R.id.rg_feedback_type);
        LinearLayout btnOtherReason = contentView.findViewById(R.id.other_reason);
        Button btnSubmit = contentView.findViewById(R.id.btn_submit);

        // 其他问题
        btnOtherReason.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                bottomDialog.dismiss();
                showOtherReasonDialog(bean);
            }
        });

        // 提交反馈
        btnSubmit.setOnClickListener(new BGAOnNoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View view) {
                String uid = UserInfoBean.getUid(mContext);
                if (TextUtils.isEmpty(uid)) {
                    toLogin();
                } else {
                    int radioButtonId = reportTypeGroup.getCheckedRadioButtonId();
                    RadioButton radioButton = contentView.findViewById(radioButtonId);
                    String reason = radioButton.getText().toString();
                    mPresenter.getVideoReport(bean.getId(), uid, reason);
                }
                bottomDialog.dismiss();
            }
        });

        bottomDialog.setContentView(contentView);
        ViewGroup.LayoutParams layoutParams = contentView.getLayoutParams();
        layoutParams.width = getResources().getDisplayMetrics().widthPixels;
        contentView.setLayoutParams(layoutParams);
        Window window = bottomDialog.getWindow();
        if (window != null) {
            window.setGravity(Gravity.BOTTOM);
            window.setWindowAnimations(R.style.BottomDialog_Animation);
        }
        bottomDialog.show();
        bottomDialog.setCanceledOnTouchOutside(true);
    }

    private void toLogin() {
        Intent intent = new Intent(mContext, LoginActivity.class);
        startActivity(intent);
    }

    /**
     * 弹出举报提示框
     *
     * @param bean 要举报的视频内容
     */
    private void showOtherReasonDialog(final InterestBean.DataBean.VideoBean bean) {
        bottomDialog = new Dialog(mContext, R.style.BottomDialog);
        @SuppressLint("InflateParams") final View contentView = LayoutInflater.from(mContext).inflate(R.layout.dialog_interest_bottom_report_other_reason, null);
        Button btnSubmit = contentView.findViewById(R.id.btn_submit);
        ImageButton btnBack = contentView.findViewById(R.id.other_reason_back);
        // 提交反馈
        btnSubmit.setOnClickListener(new BGAOnNoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View view) {
                String uid = UserInfoBean.getUid(mContext);
                if (TextUtils.isEmpty(uid)) {
                    toLogin();
                } else {
                    EditText etContent = contentView.findViewById(R.id.et_content);
                    if (TextUtils.isEmpty(etContent.getText())) {
                        showShortText("还没输入内容噢~");
                        return;
                    }
                    String reason = etContent.getText().toString();
                    mPresenter.getVideoReport(bean.getId(), uid, reason);
                }
                bottomDialog.dismiss();
            }
        });
        // 返回
        btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                bottomDialog.dismiss();
                showReportDialog(bean);
            }
        });
        bottomDialog.setContentView(contentView);
        ViewGroup.LayoutParams layoutParams = contentView.getLayoutParams();
        layoutParams.width = getResources().getDisplayMetrics().widthPixels;
        contentView.setLayoutParams(layoutParams);
        Window window = bottomDialog.getWindow();
        if (window != null) {
            window.setGravity(Gravity.BOTTOM);
            window.setWindowAnimations(R.style.BottomDialog_Animation);
        }
        bottomDialog.show();
        bottomDialog.setCanceledOnTouchOutside(true);
    }

    private void shareToWeChatWithWebPage(final InterestBean.DataBean.VideoBean bean, Context context, String url, String title, String description, final int scene) {
        final IWXAPI iwxapi = WXAPIFactory.createWXAPI(context, AppConstant.WX_APP_ID);

        if (!iwxapi.isWXAppInstalled()) {
            showShortText("您尚未安装微信");
            return;
        }

        WXWebpageObject wxWebpageObject = new WXWebpageObject();
        wxWebpageObject.webpageUrl = url;
        final WXMediaMessage wxMediaMessage = new WXMediaMessage(wxWebpageObject);
        wxMediaMessage.mediaObject = wxWebpageObject;
        wxMediaMessage.title = title;
        wxMediaMessage.description = description;
        new Thread(new Runnable() {
            @Override
            public void run() {
                thumb = NetBitmapUtils.getBitmap(HttpRequestConstant.VIDEO_PIC_HEAD + bean.getCover());
                thumb = Bitmap.createScaledBitmap(thumb, 200, 200, true);

                wxMediaMessage.setThumbImage(thumb);

                SendMessageToWX.Req req = new SendMessageToWX.Req();
                req.transaction = String.valueOf(System.currentTimeMillis());
                req.message = wxMediaMessage;
                req.scene = scene;

                iwxapi.sendReq(req);
            }
        }).start();
    }

    private void shareToQQ(String title, String summary, String url) {
        final Bundle params = new Bundle();
        params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
        params.putString(QQShare.SHARE_TO_QQ_TITLE, title);         //标题
        params.putString(QQShare.SHARE_TO_QQ_SUMMARY, summary);     //摘要
        params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, url);      //内容地址

        ThreadManager.getMainHandler().post(new Runnable() {
            @Override
            public void run() {
                mTencent.shareToQQ((MainActivity) mContext, params, mIUiListener);
            }
        });
    }

    private void shareToQZone(String title, String summary, String url) {
        final Bundle params = new Bundle();
        params.putInt(QzoneShare.SHARE_TO_QZONE_KEY_TYPE, QzoneShare.SHARE_TO_QZONE_TYPE_IMAGE_TEXT);
        params.putString(QzoneShare.SHARE_TO_QQ_TITLE, title);         //标题
        params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, summary);     //摘要
        params.putString(QzoneShare.SHARE_TO_QQ_TARGET_URL, url);      //内容地址
        params.putStringArrayList(QzoneShare.SHARE_TO_QQ_IMAGE_URL, new ArrayList<String>());

        ThreadManager.getMainHandler().post(new Runnable() {
            @Override
            public void run() {
                mTencent.shareToQzone((MainActivity) mContext, params, mIUiListener);
            }
        });
    }

    @Override
    public void onReportSuccess(CodeBean bean) {
        int code = bean.getCode();
        switch (code) {
            case 400:
                showShortText("举报失败，请重试。");
                break;
            case 200:
                showShortText("举报成功，感谢您的反馈。");
                break;
            case 404:
                showShortText("获取数据失败");
                break;
            case 403:
                showShortText("获取参数失败");
                break;
            case 406:
                showShortText("登录状态失效");
                toLogin();
                break;
        }
    }

    public void updateData() {
        mSrlMyRefreshLayout.autoRefresh();
    }

    private void initRxBus() {
        rxBus = RxBus.getInstanceBus();
        registerRxBus(MsgEvent.class, new Consumer<MsgEvent>() {
            @Override
            public void accept(@io.reactivex.annotations.NonNull MsgEvent msgEvent) {
                //根据事件类型进行处理
                if (TextUtils.equals(msgEvent.getType(), "视频详情点赞")) {
                    if (mAdapter == null || mAdapter.getList() == null) {
                        return;
                    }
                    String vid = String.valueOf(msgEvent.getPosition());
                    boolean isThing = (boolean) msgEvent.getData();
                    for (InterestBean.DataBean.VideoBean videoBean : mAdapter.getList()) {
                        if (videoBean.getId().equals(vid)) {
                            videoBean.setPraise(isThing ? 0 : 1);
                            break;
                        }
                    }
                }
            }
        });
    }

    public <T> void registerRxBus(Class<T> eventType, Consumer<T> action) {
        Disposable disposable = rxBus.doSubscribe(eventType, action, new Consumer<Throwable>() {
            @Override
            public void accept(@io.reactivex.annotations.NonNull Throwable throwable) {

            }
        });
        rxBus.addSubscription(this, disposable);
    }
}
